package com.hzdesk.media.koreabatchmatvector.adapter;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hzdesk.media.koreabatchmatvector.R;
import com.hzdesk.media.koreabatchmatvector.inter.OnclikedWiFiSetting;

/**
 * Created by Administrator on 2018/8/2.
 * 杭州席媒科技有限公司  Developers  刘传华  10
 * 佛祖镇楼 bug辟易
 */

public class SettingNetWorkAdapter extends RecyclerView.Adapter<SettingNetWorkAdapter.ViewHolder>  {

    private String[] arr = new String[]{"有线设置","无线设置","热点"};

    public void setmOnclikedWiFiSetting(OnclikedWiFiSetting mOnclikedWiFiSetting) {
        this.mOnclikedWiFiSetting = mOnclikedWiFiSetting;
    }

    private OnclikedWiFiSetting mOnclikedWiFiSetting = null;
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_setting_net_work,parent,false);
        ViewHolder mViewHolder = new ViewHolder(view);
        return mViewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        holder.tv_desc.setText(arr[position]);
        holder.ll_lin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(mOnclikedWiFiSetting != null){
                    mOnclikedWiFiSetting.onClickedItem(position);
                }
            }
        });
        holder.ll_lin.setOnHoverListener(onHoverListener);
        holder.ll_lin.setOnFocusChangeListener(onFocusChangeListener);
    }
    @Override
    public int getItemCount() {
        return arr.length;
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        private final LinearLayout ll_lin;
        private final TextView tv_desc;
        public ViewHolder(View itemView) {
            super(itemView);
            ll_lin = itemView.findViewById(R.id.item_setting_net_work_ll_lin);
            tv_desc = itemView.findViewById(R.id.item_setting_net_work_tv_desc);
        }
    }
    private View.OnHoverListener onHoverListener = new View.OnHoverListener() {
        @Override
        public boolean onHover(View v, MotionEvent event) {
            switch (event.getAction()) {
                case MotionEvent.ACTION_HOVER_ENTER:
                    v.requestFocus();
                    v.requestFocusFromTouch();
                    break;
                case MotionEvent.ACTION_HOVER_EXIT:
                    break;
                case MotionEvent.ACTION_HOVER_MOVE:
                    break;
            }
            return false;
        }
    };

    private View.OnFocusChangeListener onFocusChangeListener=new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            LinearLayout linearLayout= (LinearLayout) v;
            if (hasFocus){
                linearLayout.setBackgroundResource(R.drawable.selector_view_shape);
                ObjectAnimator scaleX=ObjectAnimator.ofFloat(v,"scaleX",1.0f,1.02f);
                ObjectAnimator scaleY=ObjectAnimator.ofFloat(v,"scaleY",1.0f,1.02f);
                ObjectAnimator translationZ=ObjectAnimator.ofFloat(v,"translationZ",0f,2.0f);
                AnimatorSet animatorSet=new AnimatorSet();
                animatorSet.play(scaleX).with(scaleY).with(translationZ);
                animatorSet.setDuration(200);
                animatorSet.start();
            }else {
                linearLayout.setBackgroundResource(R.drawable.view_shape);
                ObjectAnimator scaleX_01=ObjectAnimator.ofFloat(v,"scaleX",1.02f,1.0f);
                ObjectAnimator scaleY_01=ObjectAnimator.ofFloat(v,"scaleY",1.02f,1.0f);
                ObjectAnimator translationZ_01=ObjectAnimator.ofFloat(v,"translationZ",2.0f,0f);
                AnimatorSet animatorSet_01=new AnimatorSet();
                animatorSet_01.setDuration(200);
                animatorSet_01.play(scaleX_01).with(scaleY_01).with(translationZ_01);
                animatorSet_01.start();
            }

        }
    };
}
